package com.shqcjd.yunweiyanoperator.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.yunweiyanoperator.R;
import com.shqcjd.yunweiyanoperator.model.pojo.CompanyBean;
import com.shqcjd.yunweiyanoperator.model.pojo.SquareListBean;
import com.shqcjd.yunweiyanoperator.util.UIUtils;
import com.shqcjd.yunweiyanoperator.widget.SampleCoverVideo;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SquareVideoListAdapter extends BaseQuickAdapter<SquareListBean.ListBean, SquareVideoListAdapter.ViewHolder> {
    public SquareVideoListAdapter() {
        super(R.layout.item_square_video_list);
    }

    @Override
    protected void convert(ViewHolder helper, SquareListBean.ListBean item) {
        helper.tv_text.setText(item.title);
        helper.tv_sc.setText(item.collectNum + "");
        helper.tv_like.setText(item.likeNum + "");

        if (item.collected) {
            helper.tv_sc.setCompoundDrawablesWithIntrinsicBounds(UIUtils.getDrawable(R.mipmap.ic_sc), null, null, null);
        } else {
            helper.tv_sc.setCompoundDrawablesWithIntrinsicBounds(UIUtils.getDrawable(R.mipmap.ic_sc_no), null, null, null);
        }

        if (item.liked) {
            helper.tv_like.setCompoundDrawablesWithIntrinsicBounds(UIUtils.getDrawable(R.mipmap.ic_like), null, null, null);
        } else {
            helper.tv_like.setCompoundDrawablesWithIntrinsicBounds(UIUtils.getDrawable(R.mipmap.ic_like_no), null, null, null);
        }

        if (item.videoCategoryName != null && !item.videoCategoryName.isEmpty()) {
            helper.tv_type.setVisibility(View.VISIBLE);
            helper.tv_type.setText(item.videoCategoryName);
        } else {
            helper.tv_type.setVisibility(View.GONE);
        }


        //https://res.exexm.com/cw_145225549855002
        //防止错位，离开释放
        //gsyVideoPlayer.initUIState();
        //缩略图
        helper.video.loadCoverImage(item.imageUrl, R.mipmap.zhidao);

        helper.video.setUpLazy(item.videoUrl == null ? "" : item.videoUrl, true, null, null, item.title);

        //增加title
        helper.video.getTitleTextView().setVisibility(View.GONE);
        //设置返回键
        helper.video.getBackButton().setVisibility(View.GONE);
        //设置全屏按键功能
        helper.video.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                helper.video.startWindowFullscreen(mContext, false, true);
            }
        });
        //防止错位设置
        helper.video.setPlayTag(TAG);
        helper.video.setPlayPosition(helper.getAdapterPosition());
        //是否根据视频尺寸，自动选择竖屏全屏或者横屏全屏
        helper.video.setAutoFullWithSize(true);
        //音频焦点冲突时是否释放
        helper.video.setReleaseWhenLossAudio(false);
        //全屏动画
        helper.video.setShowFullAnimation(true);
        //小屏时不触摸滑动
        helper.video.setIsTouchWiget(false);
        //全屏是否需要lock功能

        helper.addOnClickListener(R.id.btn_details);
        helper.addOnClickListener(R.id.fl_sc);
        helper.addOnClickListener(R.id.fl_like);
        helper.fl_delete.setVisibility(View.GONE);


    }


    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.video)
        SampleCoverVideo video;
        @BindView(R.id.tv_text)
        TextView tv_text;
        @BindView(R.id.fl_sc)
        FrameLayout fl_sc;
        @BindView(R.id.tv_sc)
        TextView tv_sc;
        @BindView(R.id.fl_like)
        FrameLayout fl_like;
        @BindView(R.id.tv_like)
        TextView tv_like;
        @BindView(R.id.fl_delete)
        FrameLayout fl_delete;
        @BindView(R.id.tv_type)
        TextView tv_type;
        @BindView(R.id.btn_details)
        Button btn_details;
        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
